#pragma once

namespace base {

class HTimeConsumed
{
public:
	HTimeConsumed(unsigned long long _now) : begin_(_now) {
		last_ = begin_;
		use_total_ = 0;
	}

    HTimeConsumed(const HTimeConsumed& _rhs)
        : begin_(_rhs.begin_)
        , last_(_rhs.last_)
        , use_total_(_rhs.use_total_) {}

    const HTimeConsumed& operator=(const HTimeConsumed& _rhs) {
        if (this != &_rhs) {
            begin_ = _rhs.begin_;
            last_ = _rhs.last_;
            use_total_ = _rhs.use_total_;
        }
        return *this;
    }

public:
	inline void reset(unsigned long long _now) {
		last_ = begin_ = _now;
		use_total_ = 0;
	}
	inline void step(unsigned long long _now, unsigned long long& _use, unsigned long long& _use_total, unsigned long long& _total) {
		unsigned long long l_now = _now;
		_use = l_now - last_;
		_use_total = use_total_ += _use;
		_total = l_now - begin_;
		last_ = l_now;
	}

	inline void skip(unsigned long long _now) {
		last_ = _now;
	}

private:
	unsigned long long begin_;
	unsigned long long last_;
	unsigned long long use_total_;
};

} // namespace base

